﻿using MediatR;
using T.Vehicleservice.Domain.T.Vehicleservice.Model;
using T.Vehicleservice.Read.API.Application.Command.AccidentRecordCommand;
using T.Vehicleservice.Repository.Interface;

namespace T.Vehicleservice.Read.API.Application.CommandHandlers.AccidentRecordCommandHandler
{
    public class AccidentRecordBackfillCommandHandler : IRequestHandler<AccidentRecordBackfillCommand, AccidentRecord>
    {
        private readonly IAccidentRecordRepository _repository;
        public AccidentRecordBackfillCommandHandler(IAccidentRecordRepository repository)
        {
            _repository = repository;
        }

        public async Task<AccidentRecord> Handle(AccidentRecordBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _repository.GetAllAsync()).Where(x => x.AccidentId == request.AccidentId).FirstOrDefault();
        }
    }
}
